<template>
	<view class="root-view">
		<view class="device-layout-block">
			<view class="device-layout-mod">
				<view class="device-layout-mbody u-m-b-10">
					<block v-if="agent.length">
						<view class="textinfo-box">
							<view class="textinfo-title">代理商信息</view>
						</view>
						<view class="uform-box u-p-b-64">
							<u-form class="u-border-top" :model="form" ref="uForm">
								<u-form-item label="名称" label-width="120">
									<u-input v-model="agent.name" type="text" placeholder="" :disabled="true"/>
								</u-form-item>
								<u-form-item label="服务电话" label-width="120">
									<u-input v-model="agent.mobile" type="text" placeholder="" :disabled="true"/>
								</u-form-item>
								<u-form-item label="服务地址" label-width="120">
									<u-input v-model="agent.address" type="text" placeholder="" :disabled="true"/>
								</u-form-item>
							</u-form>
						</view>
					</block>
					<view class="textinfo-box">
						<view class="textinfo-title">绑定用户信息</view>
					</view>
					<view class="uform-box u-p-b-64">
						<u-form class="u-border-top" :model="form" ref="uForm">
							<u-form-item label="姓名" label-width="120"  :required="true">
								<u-input v-model="form.realname" type="text" placeholder="请输入姓名" />
							</u-form-item>
							<u-form-item label="身份证号" label-width="120">
								<u-input v-model="form.idcard" type="text" placeholder="请输入身份证号" />
							</u-form-item>
							<u-form-item label="所在城市" label-width="120"  :required="true">
								<u-input v-model="form.area" type="text" placeholder="请输入所在城市" :disabled="true" @click="regionShow=true"/>
								<u-picker v-model="regionShow" mode="region" @confirm="selectRegion"></u-picker>
							</u-form-item>
							<u-form-item label="详细住址" label-width="120"  :required="true">
								<u-input v-model="form.address" type="text" placeholder="请输入详细住址" />
							</u-form-item>
						</u-form>
					</view>
				</view>
				<view class="device-layout-mfoot ">
					<view class="device-layout-btns">
						<view class="btn-cell">
							<button class="coco-btn theme round lg shadow" @click="editDevice();">提交</button>
						</view>
					</view>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	import evanStep from '@/components/evan-steps/evan-step.vue';
	export default {
		components:{
			evanStep
		},
		data() {
			return {
				numList: [{
					name: '滤芯'
				}, {
					name: 'WIFI'
				}, {
					name: '设备'
				} ],
				form: {
					realname: '',
					address: '',
					area: '',
					idcard: '',
				},
				regionShow:false,
				gbWifi:null,
				bssid:'',
				disabled:false,
				device_id:0,
				name:'',
				deviceInfo:{},
				agent:{
					name:'',
					mobile:'',
					address:''
				}
			};
		},
		onLoad(opt) {
			this.device_id = opt.id ? opt.id : 0;
			this.name = opt.name ? opt.name : '';
			this.getDeviceUser();
		},
		methods:{
			jump(path) {
				this.$tools.routerTo(path);
			},
			editDevice(){
				let address = uni.getStorageSync("deviceMac");
				this.form.mac = address;
				this.$post("/api/device/bind_device_info",this.form).then(res => {
					if(res.code == 1){
						this.$u.toast("绑定成功");
						setTimeout(() => {
							uni.redirectTo({
								url:"/pages/device/add-device-result"
							})
						},1500);
					}
				})
			},
			selectRegion(e){
				console.log(e);
				this.form.area = e.province.label + '/' + e.city.label + '/' + e.area.label;
			},
			getDeviceUser(){
				// let address = uni.getStorageSync("deviceMac");
				this.$post("/api/device/get_device_info").then(res => {
					if(res.code == 1){
						this.deviceInfo = res.data.info;
						this.form.realname = res.data.info.realname;
						this.form.address = res.data.info.address;
						this.form.realname = res.data.info.realname;
						this.form.area = res.data.info.area;
						
						this.agent = res.data.agent;
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	@import "./css/device.scss";
	 
</style>
